﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;

public partial class Users_Reg : System.Web.UI.Page, ICallbackEventHandler
{
    string result="";
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = BasePage.WebTitle;
    }
    public void RaiseCallbackEvent(string eventArgument)
    {
        //可以根据传递的参数不同，调用不同的处理逻辑 
        try
        {
            string key=ConfigurationManager.AppSettings["CODE"];
            string sddm=ConfigurationManager.AppSettings["sddm"];
            string[] tmp = eventArgument.Split('|');
            string accounts = tmp[0];
            string pwd = tmp[2];
            string sex = tmp[1];
            string email = tmp[3];
            string userName = tmp[4];
            string province = tmp[5];
            string city = tmp[6];
            string area = tmp[7];
            string address = tmp[8];
            string postCode = tmp[9];
            string mobile = tmp[10];
            string phone = tmp[11];
            string Nike = accounts;
            
            //前台使用昵称注册，用户帐号自动生成


            string date = DateTime.Now.ToString();
            date = date.Replace("-", "");
            date = date.Replace(" ", "");
            date = date.Replace(":", "");

            accounts = "ID" + date;
           

            string ReCommendCustomer = new BLL.Common().GetRecommendCustomerCode();

            WEB.ERP.Service erp = new WEB.ERP.Service();
            result = erp.Customer_Add(key, sddm, accounts, userName, sex, pwd, email, address, postCode, mobile, phone, Request.UserHostAddress, ReCommendCustomer, Nike, province,city,area);
            if (result == "1" || result == "2" || result == "3")
            {                
                return;
            }
            if (result != "-2" && result != "-1" && result != "0" )
            {                
                System.Web.Security.FormsAuthentication.SetAuthCookie(result, false);
                
                //写入地址信息
                Model.V_CUSTOMER_ADDRESS custAddress = new Model.V_CUSTOMER_ADDRESS();
                custAddress.UserId = result.Split('|')[0];
                custAddress.Receiver = userName;
                custAddress.Provice = province;
                custAddress.City = city;
                custAddress.Area = area;
                custAddress.Address = address;
                custAddress.PostDM = postCode;
                custAddress.Tel = phone;
                custAddress.Mobile = mobile;
                custAddress.IsDel = "0";
                custAddress.AddTime = DateTime.Now;
                new BLL.V_CUSTOMER_ADDRESS().Add(custAddress);
                
            }
        }
        catch
        {
            result = "0";
        }
    }

    public string GetCallbackResult()
    {
        return result;
    }

}
